# -*- coding: utf-8 -*-
# @Time    : 2021/8/31 16:32
# @Author  : BrandonGT
# @FileName: Camera_Renamer.py

# Animation Camera Rename Tool

# Check if there is only one camera in the scene
# if not, raise a confirm dialog
# if is, get file name, change the camera name to link with the file name
import maya.cmds as cmds

def Camera_Renamer():

    #Define Var
    projectName = 'PVKXA'
    shapeType = 'Camera'

    # Get current file name
    fileName = cmds.file(q=True,sn=True,shn=True)
    startframe = int(cmds.playbackOptions(q=True,min=True))
    endframe = int(cmds.playbackOptions(q=True,max=True))

    # list all cameras, and select camera only name starts with Sc
    camSel_Transform = cmds.ls(sl=True,dag=True,type='transform')
    camSel_Shape = cmds.ls(sl=True, dag=True, type='camera')

    # Get Camera Version
    Temp = fileName.split('_')

    if len(Temp)>2 and len(camSel_Shape)!=0:
        scs = Temp[1]
        cam = Temp[2]

        # Form a new name of camera
        newCam = '%s_%s_%s_%i_%i' % (projectName, scs, cam, startframe, endframe)

        cmds.rename(camSel_Transform, newCam)
        cmds.warning ('Camera name has been converted')
    else:
        cmds.confirmDialog(m='File Name is not right or Not Selecting Camera, File Should Be : HGP_C0xx_Ani')

Camera_Renamer()